package month1;

public class SearchMatrix74_07 {
    public static void main(String[] args) {
        System.out.println(searchMatrix(new int[][]{{1, 3, 5, 7}, {10, 11, 16, 20}, {23, 30, 34, 60}}, 3));
    }

    static boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length, n = matrix[0].length;
        int l = 0, r = m * n - 1;
        while (l <= r) {
            int mid = l + r >> 1;
            if (matrix[mid / n][mid % n] > target) {
                r = mid - 1;
            } else if (matrix[mid / n][mid % n] < target) {
                l = mid + 1;
            } else {
                return true;
            }
        }
        return false;
    }
}
